package com.woniuxy.carlife.carlifeuserweb.controller;


import cn.hutool.core.util.ObjectUtil;
import com.woniuxy.carlife.carlifecommonsweb.exception.CarlifeGlobalException;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.Result;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.StatusCode;
import com.woniuxy.carlife.carlifecommonsweb.util.CopyUtil;
import com.woniuxy.carlife.carlifecommonsweb.util.JwtUtil;
import com.woniuxy.carlife.carlifeusermodel.dto.CardisplacementDto;
import com.woniuxy.carlife.carlifeusermodel.dto.CarinsuranceDto;
import com.woniuxy.carlife.carlifeusermodel.param.CarinsuranceParam;
import com.woniuxy.carlife.carlifeuserweb.entity.Cardisplacement;
import com.woniuxy.carlife.carlifeuserweb.entity.Carinsurance;
import com.woniuxy.carlife.carlifeuserweb.service.CarinsuranceService;
import com.woniuxy.carlife.carlifeuserweb.util.StatusMessageEnum;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zjq
 * @ClassName:c
 * @Description:车险信息
 * @date 2021/4/6 20:02
 **/

//@RestController
//@RequestMapping("/carinsurance")
//@Api(tags = "车险信息")//用于描述接口类的相关信息，作用于类上

public class CarinsuranceController {
//
//    @Resource
//    CarinsuranceService carinsuranceService;
//
//    /*
//     * 功能描述〈车险信息查看根据用户id token解析用户id〉
//     * @author:zjq
//     * @param:
//     * @return:
//     * @Date 2021/4/11 23:13
//     * @throws
//     */
//    @ApiOperation(value = "车险信息查看根据用户")
//    @GetMapping("/ordinary/findCarinsuranceByUserId")
//    public Result findCarinsuranceByUserId() {
//        ServletRequestAttributes sra =
//                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        String token = sra.getRequest().getHeader("token");
//        JwtUtil jwtUtil = new JwtUtil();
//        Claims claims = jwtUtil.parseTokenOrdinary(token);
//        if (claims == null) {
//
//            return new Result(false, StatusCode.ERROR, StatusMessageEnum.NOT_LOGGED_IN.toString());
//        }
//        Object o = claims.get("token");
//        Integer tokenUserId = Integer.valueOf(String.valueOf(o));
//
//        if (tokenUserId == null && tokenUserId == 0) {
//
//            return new Result(false, StatusCode.ERROR, StatusMessageEnum.CAN_NOT_BE_EMPTY.toString());
//        }
//        Carinsurance carinsuranceByUserId = carinsuranceService.findCarinsuranceByUserId(tokenUserId);
//        if (ObjectUtil.isNull(carinsuranceByUserId)) {
//            return new Result(false, StatusCode.ERROR, StatusMessageEnum.QUERY_IS_EMPTY.toString());
//        }
//
//        CarinsuranceDto one = CopyUtil.getOne(carinsuranceByUserId, CarinsuranceDto.class);
//
//        return new Result(true, StatusCode.OK, StatusMessageEnum.SEARCH_SUCCESSFUL.toString(), one);
//    }
//
//    /*
//     * 功能描述〈车险信息修改〉
//     * @author:zjq
//     * @param:
//     * @return:
//     * @Date 2021/4/11 23:08
//     * @throws
//     */
//    @ApiOperation(value = "车险信息修改")
//    @PostMapping("/ordinary/modifyCarinsuranceByUserId")
//    public Result modifyCarinsuranceByUserId(@ApiParam CarinsuranceParam carinsuranceParam) {
//        ServletRequestAttributes sra =
//                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        String token = sra.getRequest().getHeader("token");
//        JwtUtil jwtUtil = new JwtUtil();
//        Claims claims = jwtUtil.parseTokenOrdinary(token);
//        if (claims == null) {
//
//            return new Result(false, StatusCode.ERROR, StatusMessageEnum.NOT_LOGGED_IN.toString());
//        }
//        Object o = claims.get("token");
//        Integer tokenUserId = Integer.valueOf(String.valueOf(o));
//        if (ObjectUtil.isNull(carinsuranceParam)) {
//            return new Result(false, StatusCode.CAN_NOT_BE_EMPTY, StatusMessageEnum.CAN_NOT_BE_EMPTY.toString());
//
//        }
//        Carinsurance one = CopyUtil.getOne(carinsuranceParam, Carinsurance.class);
//        one.setUserId(tokenUserId);
//        Boolean aBoolean = carinsuranceService.modifyCarinsuranceByUserId(one);
//        return aBoolean ?
//                new Result(true, StatusCode.SUCCESSFULLY_MODIFIED, StatusMessageEnum.SUCCESSFULLY_MODIFIED.toString())
//                : new Result(false, StatusCode.FAIL_TO_EDIT, StatusMessageEnum.FAIL_TO_EDIT.toString());
//
//
//    }


}

